package com.augn.controller;

import com.augn.entity.Result;
import com.augn.utils.FileUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

@RestController
public class FileController {

    @PostMapping("/uploadImg")
    public Result<?> img(@RequestParam(value = "file") MultipartFile file){
        try{
            return Result.success(FileUtils.uploadImg(file,
                    "D:\\app\\IntelliJ IDEA 2022.1\\Workspace\\classTest\\HeavenlyCreations\\src\\main\\resources\\static\\image\\",
                    Objects.requireNonNull(file.getOriginalFilename()),
                    "http://localhost:9090/image"));
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("-1","图片上传失败");
        }
    }
}
